<!--
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2022-01-18 13:45:32
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-05-09 11:10:00
 * @FilePath: \code\cwp-front\pc-collaboration\src\components\atom\select-people\index.vue
 * @Description: 选人
-->
<template>
    <a-tooltip :title="selected.text">
        <div class="select-people" @click="selectPeople">
            <div>{{
                selected.text ? selected.text : $i18n('collaboration.default.workflowInfo.value')
            }}</div>
            <i class="syIcon sy-choose-persons1"></i
        ></div>
    </a-tooltip>
</template>
<script>
    //默认配置
    const DEFAULT_OPTIONS = {
        showBtn: false,
        panels: 'Department,Team,Post,Outworker,RelatePeople,JoinOrganization',
        selectType: 'Member',
        mode: 'open',
        minSize: 0,
        showFlowTypeRadio: false,
    };
    export default {
        name: 'SelectPeople',
        props: {
            options: {
                type: Object,
                default: () => ({}),
            },
            //已选人员
            selected: {
                type: Object,
                default: () => ({
                    //0.1绝密、0.2绝密、0.3绝密、1.1秘密、0.4
                    text: '',
                    //Member|-8067040239322578063,Member|-7716299150402043535
                    value: '',
                }),
            },
        },
        methods: {
            selectPeople() {
                const options = Object.assign({}, DEFAULT_OPTIONS, this.options);

                if (!options.params) {
                    options.params = {
                        //名称, 应该可以不要
                        // text: $('#hidTo' + commonId + ' #showToIdText').val(),
                        //格式：Member|-4300287874074918893,Member|-8067040239322578063,
                        value: this.selected.value,
                    };
                }

                if (!options.callback) {
                    //sequence 为0就从串发
                    options.callback = ({ text, value, obj: [list, sequence] }) => {
                        const data = { text, value };
                        if (sequence === '0') {
                            data.flowType = 'sequence';
                        }
                        this.$emit('update:selected', data);
                    };
                }
                console.log(this.selected);

                //设置串发
                options.flowtype = this.selected.flowType;

                //调用选人公共方法
                $.selectPeople(options);
            },
        },
    };
</script>
<style lang="scss" scoped>
    .select-people {
        @include height(30);

        position: relative;
        display: flex;
        padding-right: 10px;
        cursor: pointer;
        border: $border;
        border-radius: 4px;
        transition: all $tn linear;
        align-items: center;
        flex-direction: row-reverse;

        &:hover {
            border-color: $primary-color;
            // box-shadow: 0 0 0 2px rgb(24 144 255 / 20%);
        }

        > div {
            @include ellipsis;

            position: absolute;
            right: 30px;
            left: 10px;
        }
    }
</style>
